package ija.view;

import ija.controller.GameController;
import ija.controller.types.GameState;
import ija.model.GameModel;
import ija.model.types.FigureColor;
import ija.model.types.FigureDirection;
import ija.view.elements.PlayerPanel;
import ija.view.elements.PlayerPanel.DisplayStatus;
import ija.view.elements.PlayerPanel.PlayerType;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.util.Observable;
import java.util.Observer;

import javax.swing.JButton;
import javax.swing.JPanel;

/**
 * Testing class for GUI operations
 */

public class GameContent extends JPanel implements Observer {

    private static final long serialVersionUID = 2441331462176714393L;
    protected JButton bStartGame, bGiveUp, bMainMenu, bSaveGame, bLoadGame, bExitGame;
    protected GameController controller;
    protected GameState state;
    protected PlayerPanel pPlayer1, pPlayer2;

    // private Player[CheckersModel.] player1,player2;
    public GameContent() {
        super(new BorderLayout());
    }

    public GameContent(GameController gc) {
        super(new BorderLayout());
        this.setController(gc);
        this.getController().setView(this);
        // this.addWidgets(getController());
    }

    public GameState getState() {
        return this.state;
    }

    public void setState(GameState status) {
        this.state = status;
    }

    public void setController(GameController gc) {
        this.controller = gc;
    }

    public GameController getController() {
        return this.controller;
    }

    protected void addWidgets(GameController gc) {
        this.bStartGame = new JButton("Start game");
        this.bStartGame.setPreferredSize(new Dimension(200, 20));
        this.bStartGame.addActionListener(this.getController().createStartGameListener());

        this.bGiveUp = new JButton("Give up");
        this.bGiveUp.setPreferredSize(new Dimension(200, 20));
        this.bGiveUp.addActionListener(this.getController().createGiveUpListener());

        this.bSaveGame = new JButton("Save game");
        this.bSaveGame.setPreferredSize(new Dimension(200, 20));
        this.bSaveGame.addActionListener(this.getController().createSaveGameListener());

        this.bLoadGame = new JButton("Load game");
        this.bLoadGame.setPreferredSize(new Dimension(200, 20));
        this.bLoadGame.addActionListener(this.getController().createLoadGameListener());

        this.bMainMenu = new JButton("Main menu");
        this.bMainMenu.setPreferredSize(new Dimension(200, 20));
        this.bMainMenu.addActionListener(this.getController().createMainMenuListener());

        this.bExitGame = new JButton("Exit game");
        this.bExitGame.setPreferredSize(new Dimension(200, 20));
        this.bExitGame.addActionListener(this.getController().createExitGameListener());

        this.pPlayer1 = new PlayerPanel("Player1", FigureColor.BLACK, FigureDirection.BACKWARD,
                DisplayStatus.EDITABLE, 0);
        this.pPlayer1.setMinimumSize(new Dimension(200, 130));

        this.pPlayer1.setPlayerType(PlayerType.AI);
        this.pPlayer1.setColorType(FigureColor.BLACK);
        this.pPlayer1.setDirectionType(FigureDirection.BACKWARD);
        this.pPlayer1.addChangeListener(this.getController().createSetPlayerListener());
        this.pPlayer1.addConfirmListener(this.getController().createConfirmListener());

        this.pPlayer2 = new PlayerPanel("Player2", FigureColor.WHITE, FigureDirection.FORWARD,
                DisplayStatus.EDITABLE, 1);
        this.pPlayer2.setMinimumSize(new Dimension(200, 130));

        this.pPlayer2.setPlayerType(PlayerType.Local);
        this.pPlayer2.setColorType(FigureColor.WHITE);
        this.pPlayer2.setDirectionType(FigureDirection.FORWARD);
        this.pPlayer2.addChangeListener(this.getController().createSetPlayerListener());
        this.pPlayer2.addConfirmListener(this.getController().createConfirmListener());

    }

    @Override
    public void update(Observable o, Object obj) {
        if (o instanceof GameModel) {
            // ((GameModel) o).getDesk()
        }
    }
}
